<template>
  <div o-Container>
    <o-list v-bind:source="list.area"
            v-bind="{created:create,exported:output,modified:modify,searched:search}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.area" v-bind="{saved:save,backed:back}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_cus_area_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          area: {
            data: {
              id: 1052,
              cellData: [
                {name: "CompanyID", searchKey: "=", width: 140},//小区
                {
                  name: "ProjectID", filterKey: "=",
                  searchKey: "=", width: 170,
                  link: [{binding: "CompanyID", mapping: "CompanyID"}]
                },//过滤小区
                {name: "Name", width: 300, searchKey: "LIKE"},	// 区域名
                {name: "Code", width: 100, searchKey: "LIKE"},	// 区域名
                {name: "UniqueCode", width: 270, searchKey: "LIKE"},	// 区域名
                {name: "Note", width: 500},	// 区域描述
                {name: "CreateTime", searchKey: "BETWEEN", width: 150},//创建时间
              ],
            }
          },
        },
        item: {
          area: {
            data: {
              id: 704,
              cellData: [
                // {name: "ProjectID", link: [{mapping: "CompanyID", value: this.$parent.octopus.passport.authorization.company}]},	// 所属项目
                {name: "ProjectID"},	// 所属项目
                {name: "Name"},	// 区域名
                {name: "Code"},	// 区域名
                {name: "UniqueCode"},	// 区域名
                {name: "CreateTime"},	// 创建日期
                {name: "Note"},	// 区域描述
              ],
            },
          },
        },
        panel: {
          visible: false,
        },
      }
    },
    created: function () {
      this.init();
    },
    methods: {
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS
        if (url.indexOf("MMS/Project/Area/List") > -1) {
          //
        }
        // MDM
        else {
          this.octopus.tools.parseCell(this.list.area.data, "CompanyID").show = false;
          this.octopus.tools.parseCell(this.list.area.data, "ProjectID").show = false;
          this.octopus.tools.parseCell(this.list.area.data, "ProjectID").filterValue = this.octopus.passport.project;
        }
      },
      create: function () {
        this.item.area.data.value = null;
        this.item.area.control.load();//新增没有数据加载
        this.panel.visible = true;
      },
      output: function (data) {
        this.octopus.tips.success("下载完成。");
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
      },
      search: function (cell) {
      },
      modify: function (row) {//编辑
        this.item.area.data.value = row.ID;
        this.item.area.control.load();//编辑根据行id请求数据；然后加载
        this.panel.visible = true;
      },
      del: function (row) {
        alert("del key: " + JSON.stringify(row));
      },
      save: function (data) {
        // 刷新list
        this.octopus.tips.success(data);
        this.list.area.control.load();
        this.back();
      },
      back: function () {
        this.panel.visible = false;
      }
    },
    props: ["oData"]
  }
</script>
